package com.atguigu.srb.core.controller.api;


import com.atguigu.common.result.R;
import com.atguigu.srb.core.pojo.entity.UserInfo;
import com.atguigu.srb.core.pojo.vo.LoginVO;
import com.atguigu.srb.core.pojo.vo.RegisterVO;
import com.atguigu.srb.core.pojo.vo.UserInfoVO;
import com.atguigu.srb.core.service.UserInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 用户基本信息 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-09-13
 */
@RestController
@RequestMapping("/api/core/userInfo")
//@CrossOrigin
public class ApiUserInfoController {
    @Resource
    private UserInfoService userInfoService;
    @PostMapping("/register")
    public R register(@RequestBody RegisterVO registerVO){
        userInfoService.register(registerVO);
        return R.ok();
    }
    @PostMapping("/login")
    public R login(@RequestBody LoginVO loginVO , HttpServletRequest request){
        //String ip = request.getRemoteAddr();

        String ip = request.getHeader("X-forwarded-for");

        UserInfoVO userInfoVO = userInfoService.login(loginVO,ip);
        return R.ok().data("userInfo",userInfoVO);
    }
    @GetMapping("/checkMobile/{mobile}")
    public boolean checkMobile(@PathVariable String mobile){
      return  userInfoService.checkMobile(mobile);
    }
    @GetMapping("/test")
    public R test(HttpServletRequest request){
        String userId = request.getHeader("userId");
        System.out.println("userId:"+userId);
        return R.ok();
    }

}

